package fr.buildcity.jeu;

import java.util.ArrayList;
import java.util.List;

import org.lwjgl.input.Keyboard;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

import fr.buildcity.jeu.listeners.CaseListener;
import fr.buildcity.jeu.map.Case;
import fr.buildcity.jeu.ui.ControlPanel;

public class RenderGame extends BasicGameState {

	public static final int ID = 3;

	private static int NB_CASE = 40;

	private List<Case> plateau;

	private CaseListener listener;

	private ControlPanel controlPanel;

	@Override
	public void init(GameContainer c, StateBasedGame game)
			throws SlickException {
		listener = new CaseListener(c);
		plateau = new ArrayList<Case>();

		for (int i = 0; i < NB_CASE; i++) {
			for (int j = 0; j < NB_CASE; j++) {
				plateau.add(new Case(c, new Rectangle(i * Case.CASE_LARGEUR, j
						* Case.CASE_HAUTEUR, Case.CASE_LARGEUR,
						Case.CASE_HAUTEUR), listener, new Vector2f(i
						* Case.CASE_LARGEUR, j * Case.CASE_HAUTEUR)));
			}
		}

		// controlPanel = new ControlPanel(c,"guiBas");
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		g.setAntiAlias(true);
		g.setColor(Color.white);
		g.fillRect(0, 0, container.getWidth(), container.getHeight());
		g.setColor(Color.black);

		for (Case c : plateau) {
			c.render(container, g);
		}

		// controlPanel.renderUI(container, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		Input input = container.getInput();

		if (input.isKeyDown(Keyboard.KEY_UP)) {

		}
		if (input.isKeyDown(Keyboard.KEY_DOWN)) {

		}
		if (input.isKeyDown(Keyboard.KEY_LEFT)) {

		}
		if (input.isKeyDown(Keyboard.KEY_RIGHT)) {

		}

	}

	@Override
	public int getID() {
		return ID;
	}
}